#include "instance.h"

#include <cstdio>
#include <mutex>

#include <log.h>

GlobalObject &GlobalObject::GetInstance()
{
    LOG("outer");
    if (instance == nullptr) {
        LOG("inner");
        static std::mutex mutex;
        std::lock_guard<std::mutex> lock(mutex);
        if (instance == nullptr) {
            LOG("new");
            instance.reset(new GlobalObject());
        }
    }
    return *instance;
}

GlobalObject::GlobalObject()
{
    LOG("ctor");
}

GlobalObject::~GlobalObject()
{
    LOG("dtor");
}

void GlobalObject::Func()
{
    LOG("func");
}

int main()
{
    GlobalObject::GetInstance().Func();
    GlobalObject::GetInstance().Func();
    return 0;
}
